<template>
	<view class="record">
		<view class="nav">
			<view @click='tab(1)' :class="{'view':index==1}">提现记录 <span></span></view>
			<view @click='tab(2)' :class="{'view':index==2}">充值记录 <span></span></view>
			<view @click='tab(3)' :class="{'view':index==3}">余额明细 <span></span></view>
		</view>
		<p @click='shows'>{{Year}}-{{Month}}<u-icon name="play-right-fill" color="#3B7933" size="10"></u-icon></p>
		<u-datetime-picker :show="show" v-model="value1" @cancel='show=false' @confirm='confirm'
			mode="year-month"></u-datetime-picker>

		<image v-if="dataList.length==0" src="../../../../static/image.png"></image>

		<view class="main" v-for="item in dataList">
			<recordOne  :list="item"></recordOne>
			<!-- <recordTwo v-if="index == 101" :list="item"></recordTwo> -->
		</view>
	</view>
</template>

<script>
	import recordOne from '../../../../components/record_one/record_one.vue'
	import recordTwo from '../../../../components/record_two/record_two.vue'
	export default {
		components: {
			recordOne,
			recordTwo
		},
		data() {
			return {
				falg: false,
				datePage: 1,
				index: 1,
				show: false,
				value1: Number(new Date()),
				Year: new Date().getFullYear(),
				Month: new Date().getMonth() + 1,
				dataList: [],
			};
		},
		// 触底刷新
		onReachBottom() {
			if (this.falg) {
				this.getList(this.index);
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.dataList = [];
			this.falg = true;
			this.datePage = 1;
			this.getList(this.index);
			uni.stopPullDownRefresh();
		},
		methods: {
			tab(index) {
				this.index = index;
				this.falg = true;
				this.datePage = 1;
				this.dataList = [];
				this.getList(this.index);
			},
			confirm(res) {
				this.Year = new Date(res.value).getFullYear();
				this.Month = new Date(res.value).getMonth() + 1;
				this.show = false;
				this.datePage = 1;
				this.falg = true;
				this.dataList = [];
				this.getList(this.index);
			},
			shows() {
				this.show = true;
			},
			getList(index) {
				let params = {
					type: this.index,
					date: this.Year + '-' + this.Month,
					page:this.datePage
				};
				this.$httpRequest('/balance/getUserBalanceList', params).then(res => {
					if (res.data.last_page > res.data.current_page) {
						this.datePage++;
					} else {
						this.falg = false
					}
					this.dataList.push(...res.data.data);
				});
			},
		},
		onLoad() {
			this.getList(this.index);
		}
	}
</script>

<style lang="less">
	.record {

		&>image {
			width: 616rpx;
			height: 616rpx;
			display: block;
			margin: 100rpx auto 0;
		}

		&>.main {
			width: 690rpx;
			margin: 20rpx auto 0;
		}

		&>P {
			padding-left: 30rpx;
			display: flex;
			color: #365E44;
			font-size: 12px;

			&>.u-icon {
				transform: rotateZ(90deg) !important;
			}
		}

		&>.nav {
			width: 100%;
			padding: 22rpx 60rpx 10rpx;
			display: flex;
			box-sizing: border-box;

			&>.view {
				color: #3B7933;
				font-weight: 600;

				&>span {
					background: #3B7933;
				}
			}

			&>view {
				flex: 1;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				font-size: 15px;
				color: #999999;

				&>span {
					width: 64rpx;
					height: 10rpx;
					background: #82E3A900;
					border-radius: 10rpx;
					margin-top: 6rpx;
				}
			}
		}
	}
</style>